#include "stdio.h"
#include "unistd.h"
#include "sys/time.h"

// 计算时间的函数
int cal_sqr(int n)
{
    sleep(1);
    return n * n;
}

int main(int argc, char const *argv[])
{
    int items[5] = {1, 2, 3, 4, 5};
    int sqrs[5];

    struct timeval start, end;
    gettimeofday(&start, NULL);

    for (int i = 0; i < 5; i++)
    {
        sqrs[i] = cal_sqr(items[i]);
    }

    gettimeofday(&end, NULL);
    printf("time: %ld s\n", (end.tv_sec - start.tv_sec));

    int sum = 0;
    for (int i = 0; i < 5; i++)
    {
        sum += sqrs[i];
    }
    printf("sum: %d\n", sum);

    return 0;
}
